use aliyun_openapi_core_rust_sdk::client::rpc::RPClient;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize,  Deserialize)]
#[serde(rename_all="PascalCase")]
pub struct VideoInfo {
    pub user_data: String,
    pub size: i64,
    pub modification_time: String,
    pub preprocess_status: String,
    pub storage_location: String,
    pub tags: String,
    pub template_group_id: String,
    pub status: String,
    pub video_id: String,
    pub storage_class: String,
    pub create_time: String,
    pub download_switch: String,
    pub title: String,
    pub duration: f64,
}

#[derive(Debug, Serialize,  Deserialize)]
#[serde(rename_all="PascalCase")]
pub struct GetVideoResponse {
    pub request_id: String,
    pub video: VideoInfo,
}

#[derive(Debug, Clone)]
pub struct AliyunClient {
    client: RPClient,
}


impl AliyunClient {
    pub fn new(access_key_id: String, access_key_secret: String, endpoint: String) -> Self {
        AliyunClient {
            client: RPClient::new(access_key_id, access_key_secret, endpoint)
        }
    }

    pub async fn get_video_info(self, vid: String) -> anyhow::Result<GetVideoResponse> {
        match self.client.clone()
                    .version("2017-03-21")
                    .get("GetVideoInfo")
                    .query([("VideoId".to_string(), vid)])
                    .json::<GetVideoResponse>()
                    .await {
            Ok(v) => Ok(v),
            Err(e) => Err(e.into()),
        }
    }

} 
